package com.hpf.lease.web.admin.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hpf.lease.common.result.Result;
import com.hpf.lease.model.bean.CityInfo;
import com.hpf.lease.model.bean.DistrictInfo;
import com.hpf.lease.model.bean.ProvinceInfo;
import com.hpf.lease.web.admin.service.CityInfoService;
import com.hpf.lease.web.admin.service.DistrictInfoService;
import com.hpf.lease.web.admin.service.ProvinceInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin/region")
@Tag(name = "地区管理模块")
public class RegionController {
    @Resource
    ProvinceInfoService provinceInfoService;
    @Resource
    CityInfoService cityInfoService;
    @Resource
    DistrictInfoService districtInfoService;

    @GetMapping("/province/list")
    @Operation(summary = "查询所有的省份")
    public Result<List<ProvinceInfo>> selectAllOnProvince(){
        return Result.ok(provinceInfoService.list());
    }

    @GetMapping("/city/listByProvinceId")
    @Operation(summary = "根据省份id查询所有的市")
    public Result<List<CityInfo>> selectAllOnCity(@RequestParam Long id){
        return Result.ok(cityInfoService.list(Wrappers.lambdaQuery(CityInfo.class)
                .eq(CityInfo::getProvinceId , id)));
    }

    @GetMapping("/district/listByCityId")
    @Operation(summary = "根据市id查询所有的县")
    public Result<List<DistrictInfo>> selectAllOnDistrict(@RequestParam Long id){
        return Result.ok(districtInfoService.list(Wrappers.lambdaQuery(DistrictInfo.class)
                .eq(DistrictInfo::getCityId , id)));
    }
}
